package com.biz.primus.ms.tms.api;

import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.model.cat.enums.CatSaleStatusEnum;
import com.biz.primus.model.cat.enums.CatStatus;
import com.biz.primus.model.cat.vo.CatQueryVo;
import com.biz.primus.model.cat.vo.CatVo;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.tms.service.CatService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yanweijin
 * @date 2017/9/12
 */
@RestController
@RefreshScope
@RequestMapping("soa/catService")
public class CatApiController extends BaseApiController {

    private final CatService catService;

    @Value("${test.bus:notset}")
    private String aRefreshableProperty;

    @GetMapping("/show")
    public String sendMessage() {
        return this.aRefreshableProperty;
    }


    @Autowired
    public CatApiController(CatService catService) {
        assert catService != null;
        this.catService = catService;
    }

    @PostMapping("save")
    public CatVo save(@RequestBody CatVo cat) {
        return catService.save(cat);
    }

    @RequestMapping(value = "listByStatus", method = RequestMethod.POST)
    List<CatVo> listByStatus(@RequestParam("status") CatStatus status) {

        return catService.listByStatus(status);
    }

    @PostMapping("listBySaleStatus")
    List<CatVo> listBySaleStatus(@RequestParam("saleStatus") CatSaleStatusEnum saleStatus) {

        return catService.listBySaleStatus(saleStatus);
    }

    @ApiOperation(value = "获取指定id的猫")
    @GetMapping("get")
    public CatVo get(@RequestParam("id") Long id) {

        return catService.get(id);
    }

    @PostMapping("updateSaleStatus")
    void updateSaleStatus(@RequestParam("id") Long id, @RequestParam("saleStatus") CatSaleStatusEnum saleStatus) {

        catService.updateSaleStatus(id, saleStatus);
    }

    @ApiOperation("根据条件查询符合的猫的列表,分页展示")
    @PostMapping("findAll")
    public SpringPageVO<CatVo> catList(@RequestBody CatQueryVo queryVo) {

        return catService.findAll(queryVo);
    }

}
